package cz.fit.dpo.task1.commands;

import cz.fit.dpo.task1.Game;
import cz.fit.dpo.task1.ICommandProvider;
import cz.fit.dpo.task1.Room;
import cz.fit.dpo.task1.exceptions.RoomsAreNotNeighboursException;

public class MoveCommand implements ICommand {

	private Room room = null;

	public Room getRoom() {
		return room;
	}

	public MoveCommand(Room r) {
		this.room = r;
	}

	@Override
	public boolean execute(Game game, ICommandProvider view) {
		if ( room == null ) {
			view.printInputResult("This room doesn't exist");
		} else {
			try {
				if (game.movePlayer(room)) {
					view.printInputResult("You've successfully moved to " +room);
					return true;
				} else {
					view.printInputResult("You can't move to " + room + " - maybe you're too heavy to walk...");
				}
			} catch (RoomsAreNotNeighboursException e) {
				view.printInputResult(room + " is not neighbouring to " + game.getPlayer().isInRoom());
			}
		}
		return false;
	}

}
